home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Sprocket Framework DR2 / Sprocket Framework / UDrag.cp < prev    next >
Text File  |  1996-06-15  |  3KB  |  127 lines

  1. /*
  2.  
  3.     File:        UDrag.cp
  4.     Project:    Sprocket Framework 1.1 (DR2), released 6/15/96
  5.     Contains:    Dialog utilities
  6.     To Do:        ?
  7.  
  8.     Sprocket Major Contributors:
  9.     ----------------------------
  10.     Dave Falkenburg, producer of Sprocket 1.0
  11.     Bill Hayden,     producer of Sprocket 1.1
  12.     Steve Sisak,     producer of the upcoming Sprocket 2.0
  13.     
  14.     Pete Alexander        Steve Falkenburg    Randy Thelen
  15.     Eric Berdahl        Nitin Ganatra        Chris K. Thomas
  16.     Marshall Clow        Dave Hershey        Leonard Rosenthal
  17.     Tim Craycroft        Dave Mark            Dean Yu
  18.     David denBoer        Gary Powell
  19.     Cameron Esfahani    Jon Summers            Apple Computer, Inc.
  20.         
  21.     Comments, Additions, or Corrections:
  22.     ------------------------------------
  23.     Bill Hayden, Nikol Software <nikol@codewell.com>
  24.  
  25. */
  26.  
  27.  
  28.  
  29. #include "UDrag.h"
  30.  
  31.  
  32.  
  33. //-----------------------------------------------------------------------------
  34. // The standard UI for dragged objects is a 1-pixel outline of 
  35. // region to be dragged.
  36. // Given any region, this will turn it into the 1-pixel outline.
  37. //-----------------------------------------------------------------------------
  38. void MakeDragOutlineRegion(RgnHandle theRgn)
  39. {
  40.     RgnHandle tempRgn;
  41.     
  42.     tempRgn = NewRgn();
  43.  
  44.     if (tempRgn != NULL)
  45.         {
  46.         CopyRgn(theRgn, tempRgn);
  47.         InsetRgn(tempRgn, 1, 1);
  48.         DiffRgn(theRgn, tempRgn, theRgn);
  49.         DisposeRgn(tempRgn);
  50.         }
  51. }
  52.  
  53.  
  54. //-----------------------------------------------------------------------------
  55. // GetDropDirectory
  56. //
  57. // Given a DragReference, this returns an FSSpec for the directory where the 
  58. // item was dropped.
  59. //-----------------------------------------------------------------------------
  60. OSErr GetDropDirectory(DragReference theDrag, FSSpecPtr dirSpec)
  61. {
  62.     OSErr    returnCode;
  63.     AEDesc    theDesc;
  64.  
  65.     returnCode = GetDropLocation(theDrag, &theDesc);
  66.  
  67.     if ((theDesc.dataHandle != nil) && (returnCode == noErr))
  68.         {
  69.         AEDesc newDesc;
  70.  
  71.         returnCode = AECoerceDesc(&theDesc, typeFSS, &newDesc);
  72.  
  73.         if (returnCode == noErr)
  74.             {
  75.             BlockMoveData(*newDesc.dataHandle, dirSpec, sizeof(FSSpec));
  76.             (void) AEDisposeDesc(&newDesc);
  77.             }
  78.  
  79.         (void) AEDisposeDesc(&theDesc);
  80.         }
  81.  
  82.     return returnCode;
  83. }
  84.  
  85.  
  86. //-----------------------------------------------------------------------------
  87. // DragLandedInTrash
  88. //
  89. // If this drag landed in the trash (compared using FindFolder) this will
  90. // return true.
  91. //-----------------------------------------------------------------------------
  92. Boolean DragLandedInTrash(DragReference theDrag)
  93. {
  94.     OSErr    returnCode;
  95.     FSSpec    dirSpec;
  96.     short    trashVol;
  97.     long    trashDirID;
  98.     Boolean    wasTrashed = false;
  99.  
  100.  
  101.     returnCode = GetDropDirectory(theDrag, &dirSpec);
  102.  
  103.     if (returnCode == noErr)
  104.         {    
  105.         returnCode = FindFolder(0, kTrashFolderType, false, &trashVol, &trashDirID);
  106.         
  107.         if (returnCode == noErr)
  108.             {
  109.             CInfoPBRec    catInfo;
  110.             DirInfo        *dpb = (DirInfo    *)&catInfo;
  111.             
  112.             dpb->ioCompletion = nil;            // Find the dirID of the drop location,
  113.             dpb->ioNamePtr = dirSpec.name;        // not its parent.
  114.             dpb->ioVRefNum = dirSpec.vRefNum;
  115.             dpb->ioDrDirID = dirSpec.parID;
  116.             dpb->ioFDirIndex = 0;
  117.         
  118.             returnCode = PBGetCatInfoSync((CInfoPBPtr)dpb);
  119.             
  120.             if ((trashVol == dirSpec.vRefNum) && (trashDirID == dpb->ioDrDirID))
  121.                 wasTrashed = true;
  122.             }
  123.         }
  124.  
  125.     return wasTrashed;
  126. }
  127.